.TH std::experimental::filesystem::path::replace_filename 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::experimental::filesystem::path::replace_filename \- std::experimental::filesystem::path::replace_filename

.SH Synopsis
   path& replace_filename( const path& replacement );  (filesystem TS)

   Replaces a single filename component with replacement.

   Equivalent to the following:

 remove_filename();
 operator/=(replacement);

   The behavior is undefined if the path has no filename component (has_filename
   returns false).

.SH Parameters

   \fI(none)\fP

.SH Return value

   *this

.SH Exceptions

   May throw implementation-defined exceptions.

.SH Example


// Run this code

 #include <experimental/filesystem>
 #include <iostream>
 namespace fs = std::experimental::filesystem;

 int main()
 {
     std::cout << fs::path("/foo").replace_filename("bar") << '\\n'
               << fs::path("/").replace_filename("bar") << '\\n';
 }

.SH Output:

 "/bar"
 "bar"

.SH See also

   replace_extension replaces the extension
                     \fI(public member function)\fP
   filename          returns the filename path component
                     \fI(public member function)\fP
   remove_filename   removes filename path component
                     \fI(public member function)\fP
   has_filename      checks if the corresponding path element is not empty
                     \fI(public member function)\fP

.SH Category:
     * Noindexed pages
